package com.itheima.Test21;

import java.io.Serializable;

public class Student implements Serializable, Comparable<Student> {
    private String name;
    private int ch;
    private int math;
    private int eng;
    private int sum;

    public int getSum() {
        return ch+math+eng;
    }

    public void setSum(int sum) {
        this.sum = sum;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (ch != student.ch) return false;
        if (math != student.math) return false;
        if (eng != student.eng) return false;
        return name != null ? name.equals(student.name) : student.name == null;

    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + ch;
        result = 31 * result + math;
        result = 31 * result + eng;
        return result;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", ch=" + ch +
                ", math=" + math +
                ", eng=" + eng +
                '}';
    }

    public Student() {
    }

    public Student(String name, int ch, int math, int eng) {
        this.name = name;
        this.ch = ch;
        this.math = math;
        this.eng = eng;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getCh() {
        return ch;
    }

    public void setCh(int ch) {
        this.ch = ch;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public int getEng() {
        return eng;
    }

    public void setEng(int eng) {
        this.eng = eng;
    }

    @Override
    public int compareTo(Student o) {
        int result = o.getSum() - this.getSum();
        result = result == 0 ? this.getName().compareTo(o.getName()) : result;
        return result;
    }
}
